package com.example.zbarclient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import com.scancode.zbar.ZbarClient;
import com.scancode.zbar.ZbarResultBean;

public class MainActivity extends AppCompatActivity {
    Button button2;
    TextView textView;
    private Activity mActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mActivity = this;

        button2 = findViewById(R.id.btn_default2);

        button2.setOnClickListener(v -> startZbar());
        textView = findViewById(R.id.tv_content);
    }


    private void startZbar() {
        ZbarClient.getClient().setZbarResultListener(this, new ZbarClient.ScanResult() {
            @SuppressLint("LongLogTag")
            @Override
            public void back(ZbarResultBean result) {
                Log.e("MainActivity 收到的Zbar识别回调", result.getTag() + result.getResult());
                textView.setText("内容:" + result.getResult());
            }
        });

        ZbarClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.teal_200))
                .setScanBorderColor(ContextCompat.getColor(mActivity, R.color.white))
                .setScanTipTextColor(ContextCompat.getColor(mActivity, R.color.teal_200))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.purple_200))
                .setScanTipText("我是测试提示")
                .setOpenPhoto(true)
                .startZbar(mActivity);
    }
}